<?php require_once($_SERVER['DOCUMENT_ROOT']."/defaultconf.mex");
require_once($GLOBALS['PAD']."Modules/MX23DF2S/modconf.mex");
	MYTCONN();
	$MYT = $GLOBALS['MYT'];

	$QurStatus = '';
	$QurUser = '';

	$GET = $MYT->db_array("SELECT 
		exchange_operations.ref,
		exchange_operations.control_ref,
		exchange_operations.Time,
		exchange_operations.status,
		exchange_status.NAME AS Status,
		CliNombre AS ClientName,
		CliNumero,
		exchange_operations.main_clients_ref,
		hd_monedasiso.miso_ID AS ISO,
		SUM(exchange_operations.Amount) AS Amount,
		SUM(exchange_operations.acerto) AS acerto
	FROM exchange_operations
		INNER JOIN clientes ON clientes.CliNumero = exchange_operations.main_clients_ref
		INNER JOIN exchange_status ON exchange_status.ID = exchange_operations.status
		INNER JOIN hd_monedasiso ON hd_monedasiso.miso_Cod_elite = exchange_operations.in_currency_ref
		LEFT OUTER JOIN exchange_bags ON exchange_bags.REF = exchange_operations.malote
	WHERE exchange_operations.ref = {$_GET['RSID']}");
	
	$Serials = $MYT->db_array("SELECT miso_ID, Serial, Amount FROM exchange_serials 
		INNER JOIN hd_monedasiso ON hd_monedasiso.miso_Cod_elite = exchange_serials.refCurrency
		WHERE refOperation = {$GET[1]['ref']} AND Status != 5 
		ORDER BY ref ASC");
		
	$CallDoc = $MYT->db_array("SELECT * FROM hd_documentos
		INNER JOIN hd_documentostipos ON hd_documentostipos.tdc_Id = dtd_Tipo
		WHERE dtd_Cliente = {$GET[1]['CliNumero']}");
		
	$Qur = "SELECT ID, NAME FROM exchange_status WHERE ID = {$GET[1]['status']}";
	if ($GET[1]['status'] < 3) {
	$Qur = "SELECT ID, NAME FROM exchange_status WHERE ID IN (1,2)";
	}
	form_pr('ExcEdit','','','post'); 
	
	mn_field('button','ED','excPrint','Imprimir','','','','" style="position:absolute;top:5px;left:600px" onclick="
		newprint(\'Aplications/Export_Print.mex?OB='.$GET[1]['ref'].'&ID=01&MOD=MX23DF2S\',\'_blank\');');
?>
<div id="ExcResults" style="position:absolute;top:5px;left:300px"></div>
<label style="position:absolute;top:5px;left:10px">Operacao:</label>
<?php echo mn_field('text','ED','ref',$GET[1]['ref'],'10','10','','" style="position:absolute;top:5px;left:100px" readonly="');?>
<label style="position:absolute;top:25px;left:10px">Referencia:</label>
<?php echo mn_field('text','ED','control_ref',$GET[1]['control_ref'],'10','10','','" style="position:absolute;top:25px;left:100px" disabled readonly="');?>
<label style="position:absolute;top:45px;left:10px">Data:</label>
<?php echo mn_field('text','ED','Time',$GET[1]['Time'],'10','10','','" style="position:absolute;top:45px;left:100px" disabled readonly="');?>
<label style="position:absolute;top:65px;left:10px">Valor:</label>
<?php echo mn_field('text','ED','Amount',$GET[1]['Amount'].$GET[1]['ISO'],'10','10','','" style="position:absolute;top:65px;left:100px" disabled readonly="');?>
<label style="position:absolute;top:85px;left:10px">Resultado:</label>
<?php echo mn_field('text','ED','acerto',$GET[1]['acerto'],'10','10','','" style="position:absolute;top:85px;left:100px" disabled readonly="');?>
<label style="position:absolute;top:105px;left:10px">Estado:</label>
<?php echo mn_field('select','ED','ExcStatus',$GET[1]['status'],$Qur,'','','" style="position:absolute;top:105px;left:100px" onchange="
		document.ExcEdit.action=\'_response/rsproxy.php?pr=xc_alterexchange\';
		subform(\'ExcEdit\',\'ExcResults\');');?>
<label style="position:absolute;top:120px;left:10px">Dados do cliente</label>
<label style="position:absolute;top:140px;left:10px">N&uacute;mero de Cliente:</label>
<?php echo mn_field('text','ED','CliNumero',$GET[1]['CliNumero'],'10','10','','" style="position:absolute;top:140px;left:100px" disabled readonly="');?>
<label style="position:absolute;top:160px;left:10px">Nome:</label>
<?php echo mn_field('text','ED','ClientName',$GET[1]['ClientName'],'50','50','','" style="position:absolute;top:160px;left:100px" disabled readonly="');?>
<div style="position:absolute;top:200px;left:10px">
	<?php for ($d = 1; $d <= $CallDoc[0]; $d++) {
			echo '<div class="Line">Documento de Identificação: '.$CallDoc[$d]['tdc_Tipo'].' | N:'.$CallDoc[$d]['dtd_Numero'].'</div>';
	} ?>
</div>
<div style="position:absolute;top:300px;left:10px;margin:5px;padding:5px;width:80%;height:200px;overflow:auto"><b>Valores</b>
	<?php 
	for ($r = 1; $r <= $Serials[0]; $r++) {
	echo '<div class="Line" style="background-color:#F2F2F2">'.$Serials[$r]['Amount'].' '.$Serials[$r]['miso_ID'].', Serie: '.strtoupper($Serials[$r]['Serial']).'</div>';
	} ?></div>
</form>